package com.csgc.camera.widget.dialog

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.ProgressBar
import android.widget.TextView

import com.csgc.camera.util.dp
import com.cysd.spsyxj.R


/**
 * loading
 */
class LoadingPop (var context: Context, cancelable:Boolean) {

    private var dialog: Dialog? = null
    private var view: View? = null
    private var circleLoading:ProgressBar?=null
    private var pbLoading: ProgressBar?=null
    private var tips: TextView?=null

    init {

        view = LayoutInflater.from(context).inflate(R.layout.layout_loading_pop,null)

        circleLoading = view?.findViewById(R.id.pb_loading_circle)
        pbLoading = view?.findViewById(R.id.pb_loading)
        tips = view?.findViewById(R.id.tv_tips)

        dialog = Dialog(context, R.style.loading_dialog)
        dialog?.setContentView(view!!)
        dialog?.setCancelable(cancelable)

//        val lp = dialog?.window?.attributes
//        lp?.width = 70.dp
//        lp?.height = 70.dp
//        dialog?.window?.attributes = lp

        dialog?.setOnDismissListener {

        }

    }

    fun showLoading(isProgress:Boolean = false){
        if(isProgress){
            pbLoading?.progress = 0
            circleLoading?.visibility = View.GONE
            pbLoading?.visibility = View.VISIBLE
            tips?.visibility = View.VISIBLE
        }else{
            circleLoading?.visibility = View.VISIBLE
            pbLoading?.visibility = View.GONE
            tips?.visibility = View.GONE
        }
        dialog?.let {
            if (!it.isShowing){
                it.show()
            }
        }

    }
    fun showLoadingAndTxt(txt:String){
        tips?.text = txt
        circleLoading?.visibility = View.VISIBLE
        pbLoading?.visibility = View.GONE
        tips?.visibility = View.VISIBLE
        dialog?.let {
            if (!it.isShowing){
                it.show()
            }
        }
    }

    fun updateProgress(progress:Int){
        pbLoading?.progress = progress
    }

    fun dismissLoading(){
        dialog?.let {
            if (it.isShowing){
                it.dismiss()
            }
        }

    }



}